import {notReadNotice} from "@/api/sys/notice";
import { Notification } from 'element-ui';
import router from "@/router";

const state={
    noticeList:undefined
  }
 const mutations={
    SET_SIDEBAR_ROUTERS: (state, routes) => {
      state.sidebarRouters = routes
    },
    NOT_READ_NOTICE:(state,route)=>{
      //发送请求
      notReadNotice().then(response=>{
        state.noticeList= response.data.records
        if (router.app.$route.path=="/sys/notice"){
          return;
        }
        if (state.noticeList.length>0){
          Notification.info({
            title:"通知",
            message:"有未读通知，点击查看",
            onClick:toNotice,
          })
        }
      })

    }
  }
 const actions = {
    notReadNotice({commit}){
      return new Promise(resolve => {
        commit("NOT_READ_NOTICE")
      })
    }
  }

//跳转到通知页面，并携带参数，未阅读
function toNotice(){
  router.push({path:'/sys/notice',query:{status:0}})
}


export default {
  namespaced:true,
  state,
  mutations,
  actions
}
